package priv.conceit.sc.hoxton.common.web.aop.aspect;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import priv.conceit.sc.hoxton.common.web.aop.anno.ScheduledLock;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

/**
 * sc-hoxton
 *
 * @author Conceit
 * @since 1.0.0, 2020/9/30
 */
@Slf4j
@Component
@Aspect
public class ScheduledLockAspect {

	/**
	 * 切入点
	 */
	@Pointcut(value = "@annotation(priv.conceit.sc.hoxton.common.web.aop.anno.ScheduledLock)")
	public void pointCut(){}

	/**
	 * 环绕执行
	 * @param pjp 连接点
	 * @return Object
	 * @throws Throwable
	 */
	@Around(value = "pointCut()")
	public Object around(ProceedingJoinPoint pjp) throws Throwable {
		MethodSignature ms = (MethodSignature) pjp.getSignature();
		Method method = ms.getMethod();
		ScheduledLock scheduledLock = method.getAnnotation(ScheduledLock.class);
		TimeUnit timeOutUnit= scheduledLock.timeOutUnit();
		long timeOutValue= scheduledLock.timeOutValue();
		String key= scheduledLock.key();
		if(StrUtil.isBlank(key)){

		}

		return pjp.proceed();
	}


}
